package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.JxInstructorSubject;
import com.ruoyi.system.domain.JxInstructorStudent;
import com.ruoyi.system.mapper.JxInstructorSubjectMapper;
import com.ruoyi.system.mapper.JxInstructorStudentMapper;
import com.ruoyi.system.service.IJxAssignService;

@Service
public class JxAssignServiceImpl implements IJxAssignService {

    @Autowired
    private JxInstructorSubjectMapper instructorSubjectMapper;

    @Autowired
    private JxInstructorStudentMapper instructorStudentMapper;

    @Override
    public List<JxInstructorSubject> listInstructorSubjects(Long staffId) {
        return instructorSubjectMapper.selectByStaffId(staffId);
    }

    @Override
    public int addInstructorSubject(Long staffId, Long subjectId) {
        JxInstructorSubject e = new JxInstructorSubject();
        e.setStaffId(staffId);
        e.setSubjectId(subjectId);
        return instructorSubjectMapper.insert(e);
    }

    @Override
    public int removeInstructorSubject(Long staffId, Long subjectId) {
        return instructorSubjectMapper.deleteByStaffAndSubject(staffId, subjectId);
    }

    @Override
    public List<JxInstructorStudent> listInstructorStudents(Long staffId) {
        return instructorStudentMapper.selectByStaffId(staffId);
    }

    @Override
    public int countInstructorStudents(Long staffId) {
        return instructorStudentMapper.countByStaffId(staffId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addInstructorStudent(Long staffId, Long studentId, String remark) {
        JxInstructorStudent e = new JxInstructorStudent();
        e.setStaffId(staffId);
        e.setStudentId(studentId);
        e.setRemark(remark);
        return instructorStudentMapper.insert(e);
    }

    @Override
    public int removeInstructorStudent(Long staffId, Long studentId) {
        return instructorStudentMapper.deleteByStaffAndStudent(staffId, studentId);
    }
}


